*************************************************************************************************
*																								*
*						Flexible Wages, Bargaining, and The Gender Gap							*
*						Barbara Biasi and Heather Sarsons										*
*						Appendix Figures														*
*																								*
*************************************************************************************************


clear all
set more off
set matsize 11000
set maxvar 32000


global user = 2 // 1 = Heather, 2 = Barbara, 3 = SOM server

if $user == 1 {
cd "/Users/sarsons/Dropbox/wisconsin_women/data"
global tab = "/Users/sarsons/Dropbox/wisconsin_women/draft/tables"
global out = "/Users/sarsons/Dropbox/wisconsin_women/out"
global do = "/Users/sarsons/Dropbox/wisconsin_women/do"
}
if $user == 2 {
cd "~/Dropbox/Research/wisconsin_women/data"
global tab = "~/Dropbox/Research/wisconsin_women/draft/tables"
global out = "~/Dropbox/Research/wisconsin_women/out"
global RA = "~/Dropbox/Research/wisconsin_women/do/calvin"
global do = "~/Dropbox/Research/wisconsin_women/do"
}
if $user == 3 {
cd "~/wisconsin_women/data"
global tab = "~/wisconsin_women/draft/tables"
global out = "~/wisconsin_women/out"
global RA = "~/wisconsin_women/do/calvin"
global do = "~/wisconsin_women/do"
}

* Yale colors
global yaleblue = "0 53 107"
global ylb = "40 109 192"
global yo = "189 83 25"
global ylight2 = "217 233 242"
global ylight = "217 233 242"
global graph = "xlabel(,grid glp(dot) glc(gs10) tlc(gs10)) ylabel(,grid glp(dot) glc(gs10) tlc(gs10)) plotregion(lp(blank))"
global graphbar = "ylabel(,grid glp(dot) glc(gs10) tlc(gs10)) plotregion(lp(blank))"


do $do/QJE_R1/preamble_revision.do
replace logsalary = logsalary * 100
	global itt = "i.dist_itt i.dist_itt#i.postexp i.totalexp i.totalexp#i.postexp i.master i.master#i.postexp i.phd i.phd#i.postexp i.high i.high#i.postexp i.math i.math#i.postexp i.year i.year##i.expire"
	global expD = "i.district_code i.district_code#i.postexp i.district_code#i.totalexp i.district_code#i.totalexp#i.postexp i.district_code#i.master i.district_code#i.master#i.postexp i.district_code#i.phd i.district_code#i.phd#i.postexp i.high i.high#i.postexp i.math i.math#i.postexp i.year i.year##i.expire"
	g reltime = year-extension
	g endtime = 1 if reltime==3
	g starttime = 1 if reltime==-3
	bys id: egen fullstart = max(starttime) 
	by id: egen fullend = max(endtime)
	g balanced3 = (fullstart==1&fullend==1)
	drop endtime starttime fullstart fullend	
	g district2010 = district_code if year==2010
	bys id: egen dist_itt = max(district2010)
	drop district2010
	tempvar x
	g `x' = entry == 1 & totalexp == 1 & year <= 2011
	bysort id: egen entry_pre = max(`x')
qui tab district_code, gen(Dist)
keep if timex > -6


*----> test for pre-trends: obtain the residuals using only non-treated observations
eststo postext:  reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female if postext == 0, a($exp extension#year) vce(cluster district_code)
test _b[femx_5] = _b[femx_6] = _b[femx_7] = _b[femx_8] = _b[femx_9] = 0
local F1 : di %3.2f `e(F)'
disp `F1'
local p1 : di %3.2f `e(F)'
disp `F1'
eststo postexp:  reghdfe logsalary femx_5-femx_9 zero femx_11-femx_15 female if postexp == 0, a($exp extension#year) vce(cluster district_code)
test _b[femx_5] = _b[femx_6] = _b[femx_7] = _b[femx_8] = _b[femx_9] = 0
local F2 : di %3.2f `e(F)'
disp `F2'
coefplot	(postext, label("pre-extension (F-stat = `F1')") lcolor("$yo") lw(thick) fcolor(none) mcolor("$yo") recast(connect) ciopts(lcolor("$yo %30") recast(rcap)))   ///
			(postexp, label("pre-expiration (F-stat = `F2')") lcolor("$ylb") lw(thick) lp(dash) fcolor(none) mcolor("$ylb") recast(connect) ///
			ciopts(lcolor("$ylb %30") recast(rcap)))  ///
			 , vert keep(femx_5 femx_6 femx_7 femx_8 femx_9 zero) omitted yline(0, lcolor(gs10) lw(vthin)) ///
			 level(90) ytitle("conditional salary (100*log)") xtitle("time to CBA expiration/extension")  $graph legend(row(1) pos(6) region(lwidth(none))) ///
			 graphreg(fc(white)) xlabel(,grid glp(dot) glc(gs10) tlc(gs10)) ylabel(,grid glp(dot) glc(gs10) tlc(gs10)) ylabel(-1(0.5)1)
graph export "$out/pretrends_borusyak.png", replace

			 
*----> Estimate treatment effects using imputation estimator

* generate controls coefficients using pre-expiration data
qui eststo postext:  reg logsalary female Dist* i.year i.totalexp master phd high math i.year#i.expire i.year#i.extension if postext == 0
* "impute" values purged from the effects of the controls, also for post-expiration data
predict res, resid

* calculate mean treatment effects (in our case, mean gaps) for each time-to-treatment. cluster SE at district level
egen T = group(timex)
bootstrap, reps(300) seed(12345) cluster(district_code): eststo postexp_pre:   areg res  femx_5-femx_10   if postexp == 0, a(T)
bootstrap, reps(300) seed(12345) cluster(district_code): eststo postexp_post:  areg res  femx_11-femx_15  if postexp == 1, a(T) // note: leave out t=max exp - min exp (in our case 5)

bootstrap, reps(300) seed(12345) cluster(district_code): eststo postexp_all:  areg res  femx_5-femx_10 zero femx_11-femx_15  if postexp == 1, a(T) // note: leave out t=max exp - min exp (in our case 5)

preserve
replace femx_10 = 0
eststo baseline_ext: reghdfe logsalary femx_5-femx_9 femx_10 femx_11-femx_15 female, a($exp i.extension##i.year) vce(cluster district_code)
restore

label var zero "0"
coefplot	(postexp_pre, lcolor("$yo") lw(thick) fcolor(none) mcolor("$yo") recast(connect) ciopts(lcolor("$yo %30") recast(rcap)))   ///
			(postexp_post,lcolor("$yo") lw(thick) lp(solid) fcolor(none) mcolor("$yo") recast(connect) ciopts(lcolor("$yo %30") recast(rcap))) ///
			(baseline_ext, label("pre-expiration") lcolor("$ylb") lw(thick) lp(dash) fcolor(none) mcolor("$ylb") recast(connect) ///
			ciopts(lcolor("$ylb %30") recast(rcap)))  ///
			 , vert keep(femx_5 femx_6 femx_7 femx_8 femx_9 femx_10 femx_11 femx_12 femx_13 femx_14 femx_15) ///
			 omitted yline(0, lcolor(gs10) lw(vthin)) xline(6.5) ///
			 level(90) ytitle("conditional salary (100*log)") xtitle("time to CBA expiration/extension")  $graph legend(order(2 "Borusyak" 6 "Baseline") pos(6) row(1)) ylabel(-1.5(0.5)1)
graph export "$out/gap_borusyak.png", replace

